package com.ciwong.epaper.modules.epaper.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.ciwong.epaper.R;
import com.ciwong.epaper.modules.epaper.bean.Module;
import com.ciwong.epaper.modules.epaper.bean.ModuleContent;

import java.util.List;

/**
 * Created by res-jianpingliu on 2015/8/7.
 */
public class ShiwenAdapter extends BaseAdapter
{

    private List<ModuleContent> moduleContents;

    private LayoutInflater inflater;



    public ShiwenAdapter(Context context, Module module)
    {
        moduleContents = module.getResourceList();
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount()
    {
        return moduleContents == null ? 0 : moduleContents.size();
    }

    @Override
    public Object getItem(int position)
    {
        return moduleContents == null ? 0 : moduleContents.get(position);
    }

    @Override
    public long getItemId(int position)
    {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent)
    {
        ContentItem item = null;
        if (convertView == null)
        {
            item = new ContentItem();
            convertView = inflater.inflate(R.layout.adapter_content_shiwen_item, null);
            item.backgroudV = convertView.findViewById(R.id.item_content_shiwen_bg);
            item.nameTv = (TextView) convertView.findViewById(R.id.item_content_shiwen_tv);
            convertView.setTag(item);
        }
        else
        {
            item = (ContentItem) convertView.getTag();
        }

        ModuleContent moduleContent = moduleContents.get(position);
        item.nameTv.setText(moduleContent.getResourceName());
        return convertView;
    }

    private class ContentItem
    {
        View backgroudV;
        TextView nameTv;
    }


}
